package internet.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

//客户端
public class TcpClient {
    public static void main(String[] args) {
        Socket socket = null;
        OutputStream os = null;
        try {
            //1.得到服务器的地址
            InetAddress serverIp = InetAddress.getByName("127.0.0.1");
            //2.端口号
            int port = 8999;
            socket = new Socket(serverIp,port);
            //3.发送消息
            os = socket.getOutputStream();
            os.write("你好，我是你爹！".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                socket.close();
                os.close();
            } catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}
